package com.linux.huhx.codetools.generate;

import com.linux.huhx.codetools.constant.Constants;
import com.linux.huhx.codetools.databean.RequestBeanTwo;
import com.linux.huhx.codetools.getinfo.GetinfoFromExcel;
import com.linux.huhx.codetools.transutil.CodeToolUtils;
import org.junit.Test;

import java.text.MessageFormat;
import java.util.List;

/**
 * Created by huhx on 2017-06-14.
 */
public class GenerateCodeFromExcel {
    List<RequestBeanTwo> requestBeans = GetinfoFromExcel.getRequestInfoTwoColumn("input.xlsx");

    // 生成对应的bean类
    @Test
    public void generate_1() {
        String name, comment, line;
        for (RequestBeanTwo bean : requestBeans) {
            name = bean.getName();
            comment = bean.getComment();
            line = MessageFormat.format(Constants.FORMAT_PRIVATE_STRING, name, comment);
            System.out.println(line);
        }
    }

    // 生成请求对应的报文
    @Test
    public void generate_2() {
        String name, comment, line;
        for (RequestBeanTwo bean : requestBeans) {
            name = bean.getName();
            comment = bean.getComment();
            line = Constants.FORMAT_REQUEST_DATAGRAM;
        }
    }

    // 生成返回对应的报文
    @Test
    public void generate_3() {
        String name, comment, line;
        for (RequestBeanTwo bean : requestBeans) {
            name = bean.getName();
            comment = bean.getComment();
            line = MessageFormat.format(Constants.FORMAT_RESPONSE_DATAGRAM, name);
            System.out.println(line);
        }
    }

    // 生成field的字段
    @Test
    public void generate_4() {
        String line;
        for (RequestBeanTwo bean : requestBeans) {
            String name = bean.getName();
            line = MessageFormat.format(Constants.FORMAT_REQUEST_FIELD, CodeToolUtils.transforFirstLetterUpper(name));
            System.out.println(line);
        }
    }
}
